Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java8-11 changes consistent with 17 #576

Merged
merged 12 commits into from
Aug 15, 2024
Merged

Conversation

leerho
Copy link
Contributor

@leerho leerho commented Jun 19, 2024

This PR is targeting a DS-Java 6.1.0 release. The changes in this PR make the Java repo consistent with the just released Memory 3.0.0. This ds-java release is still targeted for Java 8 and 11 and will likely be the last release supporting Java 8 and 11. If all goes as planned, the next release will be DS-Java 7.0.0, which will be targeted at Java 17.

All of the following changes are internal and do not impact the DS-Java API.

DS-Java changes from Master to branch java8-11_changes_consistent_with_17:

common/Util.java

  • 1 javadoc

theta/Sketch

  • Deprecation removed on getMaxCompactSketchBytes
  • bug fix: getCompactSketchMaxBytes(lgK)

theta/Sketches

  • Deprecation removed on getMaxCompactSketchBytes(numEntries), Javadoc improved.

filters/bloomfilter

  • all new code for 6.1.0.
  • changes are to make the calls to Memory compatible with Memory 3.0.0.

hll/DirectAuxHashMapTest

  • WritableHandle removed

hll/DirectCouponListTest

  • WritableHandle removed

kll/KllDoublesValidationTest

  • code comment change

quantiles/DebugUnionTest

  • WritableHandle removed

quantiles/DirectQuantilesMemoryRequestTest

  • WritableHandle removed

quantiles/DoublesSketchTest

  • WritableHandle removed

quantiles/PreambleUtilTest

  • WritableHandle removed

theta/CompactSketchTest

  • WritableHandle removed

theta/DirectQuickSelectSketchTest

  • WritableHandle removed

theta/HeapifyWrapSerVer1and2Test

  • All variable renaming

theta/SketchesTest

  • bug fix: getCompactSketchMaxBytes

theta/UnionImplTest

  • WritableHandle removed

theta/UpdateSketchTest

  • removed some code comments

pom.xml

  • updated Memory dependency to 3.0.0
  • Removed some comments
  • Reorganized the section
  • updated some of the plugin versions

Readme

  • Fixed the badges
  • Removed references to "-P strict"

@leerho
Copy link
Contributor Author

leerho commented Jun 20, 2024

This must wait until DS-Memory 3.0.0 is released.

@leerho leerho marked this pull request as ready for review August 6, 2024 21:52
Copy link
Contributor

@jmalkin jmalkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find that the variable name changes in HeapifyWrapSerVer1and2Test.java actually made things any clearer. Expanding the comments above each block would have been sufficient.

The use of wmem.close() seemed arbitrary at times? Maybe it was always tied to a try-with-resources block and I didn't see that in some cases?

But we have a few tests that don't actually seem to test anything, so we should fix those. Even if the previous version was similarly flawed.


final Union union2 = SetOperation.builder().buildUnion(); //on-heap union
assertFalse(union2.isSameResource(wmem2)); //obviously not
wmem.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we not need to close wmem2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it has already been closed. In fact, if you try to close wmem2, it will throw an error.

The purpose of this test is to check the move and resize behavior when a sketch is off-heap.

  • Note on line 193 we get sufficient bytes to hold the sketch, but on line 195 we under allocate space by half. This will force the sketch to request more memory.
  • The default MemoryRequestServer will allocate new memory on the heap, and the sketch itself will move the data from wmem2 to the new heap allocation, and then resize the internal hash table into the new memory. Then the sketch will request the MRS to close wmem2, which it does.

I will add some more comments to make this test a little clearer


//The actual Memory has been re-allocated several times,
// so the the wmem reference is invalid. Use the sketch to get the last memory reference.
WritableMemory lastMem = usk1.getMemory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we get lastMem but not assert anything about it?

Copy link
Contributor Author

@leerho leerho Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real objective of this test is to be an example for the user on how the MemoryRequestServer can be used to help with limited memory scenarios where the sketch needs to expand beyond what was allocated. This is why there are extensive code comments in this test method.

The actual test that the expansion of memory occurred (several times) and the test that the sketch continued successfully is on line 67. After that, the actual capacity of the last memory allocated is printed out just for the user. There is no reason to test it, we know that it was big enough.

No change is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in order to call it a test and pretend it means anything we should assert that the size is larger than the initial size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test of success is on line 67. By definition, if line 67 passes, the memory had to grow larger than the initial size. If the memory capacity did not grow larger than the initial size, the sketch would run out of memory and the test would fail. In fact it would fail before it ever reached line 67. So putting an extra test that the memory in fact grew beyond the initial size is redundant and impotent because that extra test would either never be executed or it would always pass.

}
println(sketch.toString());
}

@Test
public void directSketchShouldMoveOntoHeapEventually2() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't actually test anything. There's no possible failure.

Rather than break it should set some sort of success flag and at the end of the test the success flag should be true. If it is not, the sketch did not actually move on heap. But right now we don't actually check that (and didn't before).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. If wmem is still alive at the end then the test failed. I just added one line.

}
} catch (final Exception e) {
throw new RuntimeException(e);
}
}

@Test
public void checkEmptyDirect() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's again no actual test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. In the process of applying a test, I discovered a minor bug in DoublesByteArrayImp::convertToByteArray(...). This test was generating an empty sketch, which should result in a returned byte[] of only 8 bytes. And it was 8 bytes, but the preLongs value in byte 0 was 2 instead of 1. This is now fixed.

@@ -97,8 +88,7 @@ public void checkConstructorKtooSmall() {
@Test//(expectedExceptions = SketchesArgumentException.class)
public void checkConstructorMemTooSmall() {
int k = 16;
try (WritableHandle h = makeNativeMemory(k/2)) {
WritableMemory mem = h.getWritable();
try (WritableMemory mem = makeNativeMemory(k/2)) {
UpdateSketch.builder().setNominalEntries(k).build(mem);
} catch (final Exception e) {
if (e instanceof SketchesArgumentException) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the expected exceptions annotation here? It's fine if there's a reason, but that should be documented and the comment in the test annotation removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. This comment applies to two adjacent test methods as well. Fixed.

@leerho
Copy link
Contributor Author

leerho commented Aug 15, 2024

Thank you for your comments!
In the process of investigating the first comment (theta/UnionImplTest). I uncovered some other issues that need to be fixed, but I will submit those under different PRs ... and try to make them as small as possible :)

@leerho leerho merged commit 16ab3da into master Aug 15, 2024
4 checks passed
@leerho leerho deleted the java8-11_changes_consistent_with_17 branch August 15, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants